<template>
  <div class="contact-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-bg"></div>
      <div class="header-content">
        <h1 class="page-title">联系我们</h1>
        <p class="page-subtitle">我们期待听到您的声音</p>
      </div>
    </div>

    <!-- 主内容区 -->
    <div class="main-content">
      <div class="container">
        <div class="contact-layout">
          <!-- 联系信息 -->
          <div class="contact-info">
            <h2 class="section-title">联系方式</h2>
            <p class="section-desc">选择您喜欢的方式与我们取得联系，我们会尽快回复您</p>
            <div class="contact-items">
              <div class="contact-item">
                <div class="item-icon">
                  <el-icon class="icon"><i-ep-message /></el-icon>
                </div>
                <div class="item-content">
                  <h3 class="item-title">电子邮箱</h3>
                  <a href="mailto:support@campustrade.com" class="item-value">support@campustrade.com</a>
                </div>
              </div>
              <div class="contact-item">
                <div class="item-icon">
                  <el-icon class="icon"><i-ep-phone /></el-icon>
                </div>
                <div class="item-content">
                  <h3 class="item-title">联系电话</h3>
                  <a href="tel:4001234567" class="item-value">400-123-4567</a>
                  <p class="item-note">工作日 9:00-18:00</p>
                </div>
              </div>
              <div class="contact-item">
                <div class="item-icon">
                  <el-icon class="icon"><i-ep-location /></el-icon>
                </div>
                <div class="item-content">
                  <h3 class="item-title">办公地址</h3>
                  <p class="item-value">校园科技园区A座501室</p>
                </div>
              </div>
              <div class="contact-item">
                <div class="item-icon">
                  <el-icon class="icon"><i-ep-chat-dot-square /></el-icon>
                </div>
                <div class="item-content">
                  <h3 class="item-title">在线客服</h3>
                  <p class="item-value">点击右下角客服图标在线咨询</p>
                  <p class="item-note">工作日 9:00-22:00
                  
周末 10:00-18:00</p>
                </div>
              </div>
            </div>

            <!-- 社交媒体 -->
            <div class="social-media">
              <h3 class="social-title">关注我们</h3>
              <div class="social-links">
                <a href="#" class="social-link">
                  <el-icon class="social-icon"><i-ep-wechat /></el-icon>
                </a>
                <a href="#" class="social-link">
                  <el-icon class="social-icon"><i-ep-weibo /></el-icon>
                </a>
                <a href="#" class="social-link">
                  <el-icon class="social-icon"><i-ep-document /></el-icon>
                </a>
                <a href="#" class="social-link">
                  <el-icon class="social-icon"><i-ep-message-circle /></el-icon>
                </a>
              </div>
            </div>
          </div>

          <!-- 联系表单 -->
          <div class="contact-form-wrapper">
            <h2 class="section-title">发送消息</h2>
            <p class="section-desc">填写下方表单，我们会在24小时内回复您</p>
            <el-form ref="contactFormRef" :model="contactForm" :rules="contactRules" label-width="80px">
              <el-form-item label="姓名" prop="name">
                <el-input v-model="contactForm.name" placeholder="请输入您的姓名"></el-input>
              </el-form-item>
              <el-form-item label="邮箱" prop="email">
                <el-input v-model="contactForm.email" placeholder="请输入您的邮箱"></el-input>
              </el-form-item>
              <el-form-item label="电话" prop="phone">
                <el-input v-model="contactForm.phone" placeholder="请输入您的电话（选填）"></el-input>
              </el-form-item>
              <el-form-item label="类型" prop="type">
                <el-select v-model="contactForm.type" placeholder="请选择消息类型">
                  <el-option label="咨询问题" value="question"></el-option>
                  <el-option label="建议反馈" value="suggestion"></el-option>
                  <el-option label="投诉举报" value="complaint"></el-option>
                  <el-option label="其他" value="other"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="消息" prop="message">
                <el-input
                  v-model="contactForm.message"
                  type="textarea"
                  placeholder="请输入您的消息内容"
                  rows="5"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-checkbox v-model="contactForm.agree">
                  我已阅读并同意<a href="/privacy" target="_blank" class="privacy-link">《隐私政策》</a>
                </el-checkbox>
              </el-form-item>
              <el-form-item>
                <el-button
                  type="primary"
                  :loading="isSubmitting"
                  @click="submitForm"
                  class="submit-button"
                >
                  发送消息
                </el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>

        <!-- 常见问题推荐 -->
        <div class="faq-section">
          <h2 class="section-title">常见问题</h2>
          <p class="section-desc">您可能会问的问题，点击查看详情</p>
          <el-collapse class="faq-collapse">
            <el-collapse-item title="如何发布二手商品？" name="1">
              <p class="faq-content">登录账号后，点击导航栏的"发布商品"按钮，按照页面提示填写商品信息、上传图片、设置价格等，完成后点击"发布"即可。</p>
            </el-collapse-item>
            <el-collapse-item title="如何确保交易安全？" name="2">
              <p class="faq-content">我们建议您通过平台进行担保交易，避免线下直接转账；当面交易时选择人多的公共场所；收到商品后及时检查，确认无误再确认收货。</p>
            </el-collapse-item>
            <el-collapse-item title="遇到商品质量问题怎么办？" name="3">
              <p class="faq-content">如果收到的商品与描述不符，请在24小时内联系卖家协商解决；协商不成可以联系平台客服介入处理，我们会根据交易记录和证据进行公正裁决。</p>
            </el-collapse-item>
          </el-collapse>
          <div class="faq-more">
            <router-link to="/faq" class="more-link">查看更多问题 <el-icon class="more-icon"><i-ep-arrow-right /></el-icon></router-link>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

const contactFormRef = ref(null)
const isSubmitting = ref(false)

// 联系表单数据
const contactForm = reactive({
  name: '',
  email: '',
  phone: '',
  type: '',
  message: '',
  agree: false
})

// 表单验证规则
const contactRules = {
  name: [
    { required: true, message: '请输入您的姓名', trigger: 'blur' }
  ],
  email: [
    { required: true, message: '请输入您的邮箱', trigger: 'blur' },
    { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
  ],
  phone: [
    { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
  ],
  type: [
    { required: true, message: '请选择消息类型', trigger: 'change' }
  ],
  message: [
    { required: true, message: '请输入您的消息内容', trigger: 'blur' },
    { min: 10, message: '消息内容至少10个字符', trigger: 'blur' }
  ],
  agree: [
    { required: true, message: '请阅读并同意隐私政策', trigger: 'change' }
  ]
}

// 提交表单
const submitForm = async () => {
  if (!contactFormRef.value) return
  
  try {
    await contactFormRef.value.validate()
    isSubmitting.value = true
    
    // 模拟提交请求
    setTimeout(() => {
      ElMessage.success('消息发送成功，我们会尽快与您联系！')
      // 重置表单
      contactFormRef.value.resetFields()
      isSubmitting.value = false
    }, 1000)
  } catch (error) {
    console.error('表单验证失败', error)
  }
}

onMounted(() => {
  // 设置页面标题
  document.title = '联系我们 - 校园二手交易平台'
})
</script>

<style scoped>
.contact-container {
  min-height: calc(100vh - 160px);
  display: flex;
  flex-direction: column;
}

/* 页面头部样式 */
.page-header {
  position: relative;
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: white;
  overflow: hidden;
}

.header-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.9) 0%, rgba(118, 75, 162, 0.9) 100%);
  z-index: 1;
}

.header-content {
  position: relative;
  z-index: 2;
}

.page-title {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 15px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.page-subtitle {
  font-size: 16px;
  opacity: 0.9;
}

/* 主内容区样式 */
.main-content {
  flex: 1;
  padding: 60px 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.contact-layout {
  display: flex;
  gap: 40px;
  margin-bottom: 80px;
}

/* 联系信息样式 */
.contact-info {
  flex: 1;
  min-width: 300px;
}

.section-title {
  font-size: 28px;
  font-weight: 700;
  color: #333;
  margin-bottom: 15px;
  position: relative;
  display: inline-block;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 0;
  width: 60px;
  height: 4px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
}

.section-desc {
  color: #666;
  margin-bottom: 30px;
  font-size: 16px;
}

.contact-items {
  margin-bottom: 40px;
}

.contact-item {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
  align-items: flex-start;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 10px;
  transition: all 0.3s ease;
}

.contact-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  background: white;
}

.item-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-icon .icon {
  font-size: 24px;
  color: #667eea;
}

.item-content {
  flex: 1;
}

.item-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.item-value {
  font-size: 16px;
  color: #667eea;
  text-decoration: none;
  transition: color 0.3s ease;
}

.item-value:hover {
  color: #764ba2;
  text-decoration: underline;
}

.item-note {
  font-size: 14px;
  color: #999;
  margin-top: 5px;
}

/* 社交媒体样式 */
.social-media {
  padding: 30px;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
  border-radius: 12px;
  text-align: center;
}

.social-title {
  font-size: 20px;
  font-weight: 600;
  color: #333;
  margin-bottom: 20px;
}

.social-links {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.social-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: white;
  color: #667eea;
  font-size: 24px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.social-link:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
  color: white;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* 联系表单样式 */
.contact-form-wrapper {
  flex: 1;
  min-width: 300px;
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
}

.submit-button {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  transition: all 0.3s ease;
}

.submit-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.privacy-link {
  color: #667eea;
  text-decoration: none;
}

.privacy-link:hover {
  text-decoration: underline;
}

/* 常见问题样式 */
.faq-section {
  background: #f8f9fa;
  padding: 40px;
  border-radius: 12px;
}

.faq-collapse {
  margin-top: 20px;
}

:deep(.el-collapse-item__header) {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  padding: 15px 20px;
  border-radius: 8px;
  margin-bottom: 10px;
  background: white;
  transition: all 0.3s ease;
}

:deep(.el-collapse-item__header:hover) {
  background: rgba(102, 126, 234, 0.05);
  color: #667eea;
}

:deep(.el-collapse-item__content) {
  padding: 20px;
  background: white;
  border-radius: 0 0 8px 8px;
  margin-top: -10px;
}

.faq-content {
  color: #666;
  line-height: 1.8;
}

.faq-more {
  text-align: center;
  margin-top: 30px;
}

.more-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #667eea;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.3s ease;
}

.more-link:hover {
  color: #764ba2;
  transform: translateX(5px);
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .contact-layout {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .page-title {
    font-size: 30px;
  }
  
  .section-title {
    font-size: 24px;
  }
  
  .contact-form-wrapper {
    padding: 30px 20px;
  }
  
  .faq-section {
    padding: 30px 20px;
  }
}

@media (max-width: 480px) {
  .page-header {
    height: 200px;
  }
  
  .page-title {
    font-size: 24px;
  }
  
  .contact-item {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  
  .social-links {
    flex-wrap: wrap;
  }
}
</style>